package se.webbzon.oschi01.nbt;

import java.util.Arrays;

import se.webbzon.oschi01.nbt.TagEvent.Action;

public class ByteArrayTag extends AbstractTag<byte[]> {
	
	private byte[] data;
	
	public ByteArrayTag(TagFactory<byte[]> factory, String tagName, byte[] data) {
		super(factory, tagName);
		this.data = data;
	}

	@Override public long size() {
		return data.length;
	}

	@Override public byte[] getValue() {
		return data;
	}

	@Override public void setValue(byte[] value) {
		this.data = value;
		broadcastEvent(new TagEvent(this,Action.CHANGED,value));
	}

	@Override public Class<byte[]> getValueClass() {
		return byte[].class;
	}

	@Override public ByteArrayTag clone() {
		byte[] copy = Arrays.copyOf(data,data.length);
		return new ByteArrayTag(getFactory(),this.toString(),copy);
	}

}
